<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    #big {
      width: 400px;
      height: 400px;
    }

    #big img {
      width: 400px;
      height: 400px;
    }

    #small {
      width: 400px;
      height: 100px;
      display: flex;
      justify-content: space-around;
    }

    #small img {
      width: 90px;
      height: 100px;
    }
  </style>
</head>

<body>
  <div>
    <div id="big">
      <img src="./img/1.png" alt="">
    </div>
    <div id="small">
      <img src="./img/1.png" alt="">
      <img src="./img/2.png" alt="">
      <img src="./img/3.png" alt="">
      <img src="./img/4.png" alt="">
    </div>
  </div>
  <script>
    // 获取所有小图
    var imgs = document.querySelectorAll("#small img");
    // 获取大图
    var bigimg = document.querySelector("#big img")
    // 给所有小图绑定点击事件
    for (var i = 0; i < imgs.length; i++) {
      imgs[i].onclick = function () {
        // var smallSrc = this.src;//获取当前点击的图片的src 
        // bigimg.src = smallSrc;

        var smallSrc = this.getAttribute("src");//获取当前点击的图片的src 
        bigimg.setAttribute("src", smallSrc)
      }
    }



  </script>
</body>

</html>